package com.hzj.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzj.pojo.HospitalInfo;
import com.hzj.service.HospitalInfoService;
import com.hzj.service.ScheduleService;
import com.hzj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 医生日程安排表 前端控制器
 * </p>
 *
 * @author hzj
 * @since 2021-04-26
 */
@RestController
@RequestMapping("/provider/admin/hosp/schedule")
public class ScheduleController {
    @Autowired
    ScheduleService ss;
    @Autowired
    HospitalInfoService his;

    @PostMapping("/getScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getScheduleRule(@PathVariable Integer page, @PathVariable Integer limit, @PathVariable String hoscode, @PathVariable Integer depcode) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("hoscode", hoscode);
        wrapper.eq("depcode", depcode);
        wrapper.groupBy("work_date");
        //根据上面条件分组分页数据，根据时间分组
        Page page1 = ss.page(new Page(page, limit), wrapper);
        Map<String, Object> map = new HashMap();
        map.put("bookingScheduleList", page1);
        QueryWrapper wrapper1 = new QueryWrapper();
        wrapper1.eq("hoscode", hoscode);
        //查询医院数据
        HospitalInfo one = his.getOne(wrapper1);
        map.put("baseMap", one);

        return Result.ok(map);
    }

    @PostMapping("/getScheduleDetail/{hoscode}/{depcode}/{workDate}")
    Result getScheduleDetail(@PathVariable String hoscode, @PathVariable Integer depcode, @PathVariable String workDate) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("hoscode", hoscode);
        wrapper.eq("depcode", depcode);
        wrapper.eq("work_date", workDate);
        List list = ss.list(wrapper);

        return Result.ok(list);
    }

}

